﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test3
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> intList = new List<int>();
            for(int i = 2; i <= 100; ++i)
            {
                intList.Add(i);
            }
            int factor = 2;
            while (factor <= 100)
            {
                //从factor的倍数开始，即factor*2   每次加上factor
                for(int i = factor * 2; i <= 100; i += factor)
                {
                    if (intList.Contains(i))
                    {
                        intList.Remove(i);
                    }
                }
                ++factor;
            }
            //遍历输出剩余的数
            foreach(int n in intList)
            {
                Console.Write(n + " ");
            }
            Console.ReadKey();
        }
    }
}
